<!doctype html>
<html>
<head>
  <meta charset="utf-8"/>
  <meta http-equiv="X-UA-Compatible" content="IE=7; IE=EmulateIE9; IE=10" />
  <meta name="keywords" content="makeRouteRequest,onRouteCalculated" />
  <title>HERE Maps API Example: Calculating a route between two points</title>
  <!-- Set up constants such as APP ID and token -->
  <script type="text/javascript" src="libs/hereAppIdAndToken.js"></script>
  <!-- Bootstrap jQuery Library -->
  <script type="text/javascript" src="libs/jQl.min.js"></script>

  <!-- Asynchronously the HERE Maps API for JavaScript -->
  <script type="text/javascript" src="libs/hereAsyncLoader.js"
    id="HereMapsLoaderScript"
    data-map-container="mapContainer"
    data-params="maps,directions"
    data-callback="afterHereMapLoad" >
  </script>
  <link rel="icon" href="http://here.com/favicon.ico"/>
  <!--<link href="http://developer.here.com/html/css/main.css" rel="stylesheet" />-->
</head>
<body>
  <h1>Calculating a route between two points</h1>
  <p>This example uses the routing manager to calculate a route between Berlin and Paris.
  </p>
  <div id="mapContainer" style="width:540px; height:334px;"></div>

<script id="example-code" data-categories="routing" type="text/javascript" >
//<![CDATA[
var map,
  router;

function onRouteCalculated(observedRouter, key, value) {
  if (value === 'finished') {
    var routes = observedRouter.getRoutes(),
      mapRoute =
        new nokia.maps.routing.component.RouteResultSet(
          routes[0]
        ).container; //first option found
    map.objects.add(mapRoute);

    //Zoom to the bounding box of the route
    map.zoomTo(mapRoute.getBoundingBox(), false, 'default');
  } else if (value === 'failed') {
    alert('The routing request failed.');
  }
}

function makeRouteRequest() {
  var waypoints = new nokia.maps.routing.WaypointParameterList(),
    modes = [{
      type: 'shortest',
      transportModes: ['car'],
      options: 'avoidTollroad',
      trafficMode: 'default'
    }];

  waypoints.addCoordinate(
    new nokia.maps.geo.Coordinate(52.500556, 13.398889)
  ); // Berlin, Germany
  waypoints.addCoordinate(
    new nokia.maps.geo.Coordinate(48.856667, 2.350833)
  );  // Paris, France

  router = new nokia.maps.routing.Manager();
  router.addObserver('state', onRouteCalculated);
  router.calculateRoute(waypoints, modes);
}



function afterHereMapLoad(theMap) {
  map = theMap;
  makeRouteRequest();
}
//]]>
</script>
<script type="text/javascript" src="libs/prettyprint.js"></script>
</body>
</html>